import json

from flask import Flask, render_template, request
from liuhao1.settings.default import DefaultConfig


def create_flask_app(config):
    app = Flask(__name__)
    app.config.from_object(config)

    return app


app = create_flask_app(DefaultConfig)


# @app.route('/register', methods=['post', 'get'])
# def index():
#     if request.method == 'POST':
#
#         return render_template('login.html')
#     if request.method == 'GET':
#         return render_template('index.html')


# @app.route('/file', methods=['POST'])
# def file():
#     file = request.files.get('name')
#     img_name = file.filename
#     # 创建响应对象
#     resp = make_response(img_name)
#     # 指定响应数据的类型
#     resp.headers['Content-Type'] = 'image/jpg'
#
#     return resp


@app.route('/js', methods=['post'])
def js():
    data_ = {
        "name": request.form.get('name')
    }
    return json.dumps(data_)


if __name__ == '__main__':
    app.run()
